package com.tpay.client.place;

import com.google.inject.Inject;
import com.google.web.bindery.event.shared.EventBus;
import com.gwtplatform.mvp.client.proxy.PlaceManagerImpl;
import com.gwtplatform.mvp.client.proxy.PlaceRequest;
import com.gwtplatform.mvp.client.proxy.TokenFormatter;
import com.tpay.client.NameTokens;

public class PayPlaceManager extends PlaceManagerImpl {
	private final PlaceRequest defaultPlaceRequest;
	
	@Inject
	public PayPlaceManager(EventBus eventBus, TokenFormatter tokenFormatter, @DefaultPlace String defaultNameToken) {
		super(eventBus, tokenFormatter);
		
		this.defaultPlaceRequest = new PlaceRequest(defaultNameToken);
	}

	@Override
	public void revealDefaultPlace() {
		this.revealPlace(defaultPlaceRequest);
	}

	@Override
	public void revealErrorPlace(String invalidHistoryToken) {
		PlaceRequest placeRequest = new PlaceRequest(NameTokens.errorPage);
		this.revealPlace(placeRequest);
	}

	@Override
	public void revealUnauthorizedPlace(String unauthorizedHistoryToken) {
		PlaceRequest placeRequest = new PlaceRequest(NameTokens.loginPage);
		placeRequest = placeRequest.with("redirect", unauthorizedHistoryToken);
		this.revealPlace(placeRequest);
	}
}
